//
//  BuyTicketsViewController.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/11/27.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "BuyTicketsViewController.h"
#import "H5BaseViewController.h"
#import "SegmentTapView.h"
#import "GuGuLandscapeTableView.h"
#import "RegularBusViewController.h"
#import "ThroughBusViewController.h"

@interface BuyTicketsViewController () <GuGuIndexDelegate,SegmentTapViewDelegate>
@property (nonatomic, strong)  SegmentTapView *segment;
@property (nonatomic , strong) GuGuLandscapeTableView *contentTable;
@property (nonatomic , strong) NSMutableArray *controllers;
@end

@implementation BuyTicketsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setCityBtnItem];
    [self initSegmentTapView];
    [self initContentTableView];
    [self addNotification];
}

-(void)addNotification{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setCityBtnItem) name:GPSSuccess object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setCityBtnItem) name:ResetLocation object:nil];
}

// 配置头部视图
-(void)initSegmentTapView{
    self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0, 0 , [UIScreen width] , 44)
                                           withDataArray:@[@"班车",@"直通车"]];
    
    self.segment.delegate = self;
    self.segment.lineWidth = 60;
    [self.view addSubview:self.segment];
}

/**
 * segment点击回调
 * @param index
 */
-(void)selectedIndex:(NSInteger)index{
    [self.contentTable selectIndex:index];
}

-(void)initContentTableView
{
    self.controllers = [[NSMutableArray alloc ] init];
    [self initRegularBusViewController];
    [self initThroughBusViewController];
    self.contentTable = [[GuGuLandscapeTableView alloc]
                         initWithFrame:CGRectMake(0, 44, [UIScreen width], self.view.frame.size.height - 104)
                         Array:self.controllers];
    self.contentTable.swipeDelegate = self;
    [self.view addSubview:self.contentTable];
}

// 班车
-(void)initRegularBusViewController{
    
    RegularBusViewController *regularBusViewController = (RegularBusViewController *)[RegularBusViewController getViewControllerFromSbName:@"BuyTickets" viewControllerName:@"RegularBusViewController"];
    regularBusViewController.buyTicketsViewController  = self;
    [self.controllers addObject:regularBusViewController];
}

// 直通车
-(void)initThroughBusViewController{
    ThroughBusViewController *regularBusViewController = (ThroughBusViewController *)[RegularBusViewController getViewControllerFromSbName:@"BuyTickets" viewControllerName:@"ThroughBusViewController"];
    regularBusViewController.buyTicketsViewController  = self;
    [self.controllers addObject:regularBusViewController];
}

-(void)barSelectedIndexChanged:(NSInteger)newIndex{
    [self.segment selectIndex:newIndex];
}


-(void)cityAction{
    UINavigationController *cityNavigation = (UINavigationController *)[BaseViewController getInitialViewControllerFromSbName:@"City"];
    [self presentViewController:cityNavigation animated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
